<template>
  <div class="order">
    <el-table
      :data="tableData"
      stripe
      border
      style="width: 100%; margin: 30px 0"
    >
      <el-table-column prop="contractCode" label="合同编号"> </el-table-column>
      <el-table-column prop="signDate" label="签订日期"> </el-table-column>
      <el-table-column prop="totalPice" label="金额"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="download(scope.row)" type="text" size="small"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getorderlist, downloadpdf } from "../../apis/index";
export default {
  name: "order",
  components: {},
  data() {
    return {
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
    };
  },
  computed: {},
  created() {
    getorderlist()
      .then((res) => {
        this.tableData = res.data.data;
      })
      .catch(() => {});
  },
  methods: {


    //url请求参数
//params请求参数
//filename文件名称


    download(url) {

      const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
      // console.log(url,4444);
      downloadpdf(url.id)
        .then((res) => {
         

          const content = res.data
          const blob = new Blob([content], { type: `application/pdf;charset-UTF-8`})
          var name = '合同.pdf'
          const elink = document.createElement('a')
          elink.download = name
          elink.style.display = 'none'
          elink.href = URL.createObjectURL(blob)
          document.body.appendChild(elink)
          elink.click()
          URL.revokeObjectURL(elink.href) // 释放URL 对象
          document.body.removeChild(elink)

          loading.close();
          
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.order {
}
</style>